package httpserver

import (
	"gitee.com/fierce_wolf/go-fox-edge-common/commEnv"
	"github.com/gin-gonic/gin"
	"io"
)

var (
	Server *server
)

func init() {
	Server = &server{}
	gin.SetMode(gin.DebugMode)
	gin.DefaultWriter = io.MultiWriter()
	Server.engine = gin.Default()
	Server.router = make(map[string]interface{})

	respond := &DefaultRespond{}
	Server.Respond = respond
}

func StartServer(certFile, keyFile string) {
	go Server.startServer("", "")
}
func StartHttpServer() {
	go Server.startServer("", "")
}
func StartHttpsServer() {
	certFile, _ := commEnv.GetArg("https.certFile")
	keyFile, _ := commEnv.GetArg("https.keyFile")

	go Server.startServer(certFile.(string), keyFile.(string))
}

func GetRouter() map[string]interface{} {
	return Server.router
}
